<div class="row-fluid">
    <div class="box span12">
        <div class="box-header">
            <h2><i class="icon-user"></i><span class="break"></span>
                <?php
                if ($model->isNewRecord)
                    echo 'Create New Customer';
                else
                {
                    echo 'Edit Customer';
                }
                ?>
            </h2>
        </div>

        <div class="box-content">
            <div class="row-fluid">
                <?php if (Yii::app()->user->hasFlash('success')): ?>
                    <div class="alert alert-success">
                        <button type="button" class="close" data-dismiss="alert">×</button>
                        <strong>All done!</strong> <?php echo Yii::app()->user->getFlash('success'); ?>
                    </div>
                    <?php // endif; ?>
                <?php elseif (Yii::app()->user->hasFlash('error')): ?>
                    <div class="alert alert-error">
                        <button type="button" class="close" data-dismiss="alert">×</button>
                        <strong>Failed!</strong> <?php echo Yii::app()->user->getFlash('error'); ?>
                    </div>
                <?php endif; ?>


                <?php
                $form = $this->beginWidget('CActiveForm', array(
                    'id'                     => 'user-form',
//                    'enableAjaxValidation' => true,
                    'enableClientValidation' => true,
                    'htmlOptions'            => array(
                        'class'   => 'form-horizontal',
                        'enctype' => 'multipart/form-data',
                    ),
                    'focus'                  => array($model, 'username'),
                    'clientOptions'          => array(
                        'validateOnSubmit' => true,
                    ),
                ));
                ?>

                <fieldset>
                    <div class="span6">
                        <div class="control-group">
                            <?php echo CHtml::label('Photo', 'photo', array('class' => 'control-label')); ?>
                            <div class ="controls">
                                <div class="user_photo">
                                    <img src="<?php echo $model->publicPhoto ?>" alt="User photo">
                                </div>
                                <input type="file" name="file"/>
                            </div>
                        </div>                        

                        <div class="control-group">
                            <?php echo CHtml::label('Email', 'email', array('class' => 'control-label')); ?>
                            <div class ="controls">
                                <?php if (!$model->isNewRecord): ?>
                                    <?php
                                    echo CHtml::textField('email', $model->user->email, array('readonly' => true));
                                    ?>
                                <?php else: ?>
                                    <?php
                                    echo $form->textField($model, 'email');
                                    ?>
                                <?php endif; ?>
                                <font color="red"> <?php echo $form->error($model, 'email'); ?> </font>
                            </div>
                        </div>

                        <div class="control-group">
                            <?php echo $form->labelEx($model, 'status', array('class' => 'control-label')) ?>
                            <div class ="controls">         
                                <?php $model->status = $model->status ? $model->status : Users::STATUS_ACTIVE ?>
                                <?php
                                echo CHtml::activeRadioButtonList($model, 'status', Users::getArrayStatus(), array(
                                    'template' => '<label class="radio">{input} {label}</label>'
                                ))
                                ?>
                            </div>
                        </div>
                        <div class="control-group">
                            <div class ="controls">
                                <a href="<?php echo Yii::app()->createUrl('appointment/index') ?>" class="btn btn-success btn-large">
                                    <i class="icon-book"></i> Book Appointment                                            
                                </a>
                            </div>
                        </div>

                        <?php if (!$model->isNewRecord): ?>
                            <?php
                            echo $this->renderPartial('_recent_appt');

                            if (isset($history_appoint) && $history_appoint != NULL)
                                echo $this->renderPartial('_history', array('history_appoint' => $history_appoint));
                            echo $this->renderPartial('_total_spent', array(
                                'model' => $model
                            ));
                            ?>
                        <?php endif; ?>
                    </div>

                    <?php
                    if ($model->isNewRecord)
                        $user = new Users();
                    else
                        $user = $model->user;
                    echo $this->renderPartial('_form', array(
                        'form'           => $form,
                        'model'          => $user,
                        'model_customer' => $model
                    ));
                    ?>
                    <div class="span6">
                        <?php
                        if (isset($notes))
                            echo $this->renderPartial('_note', array(
                                'notes' => $notes,
                                'pages' => $note_pages,
                                'model' => $model
                            ));
                        ?>
                    </div>
                    <div class="clearfix"></div>                    
                    <hr>
                    <?php
                    echo CHtml::submitButton('Save', array('class' => 'btn btn-primary'));
                    ?>
                    <?php echo CHtml::resetButton('Reset', array('class' => 'btn', 'id' => 'btn-reset')); ?>
                </fieldset>
                <?php $this->endWidget(); ?>
            </div>
        </div>
    </div>
</div>
